package com.estar.integaration.strategy;

import com.estar.integaration.entity.paymentPlanEntity.PurchaseOrderDetail;
import com.estar.integaration.entity.paymentPlanEntity.SupplierAccountPeriod;
import lombok.AllArgsConstructor;
import org.apache.xpath.operations.Bool;

import java.util.List;
import java.util.Map;

/**
 * Author: YJL
 * Date: 2022/2/18 15:44
 * 未付全款-已入库-未到票 NYN
 **/
@AllArgsConstructor
public class StrategyNYN extends Strategy {

  Map<String, SupplierAccountPeriod> supplierAccountPeriodMap;

  /**
   * 设置时间和应付的钱
   * @param purchaseOrderDetailList
   * @param purchaseOrderDetail
   * @return
   */
  @Override
  public Boolean setExpectDate(List<PurchaseOrderDetail> purchaseOrderDetailList,PurchaseOrderDetail purchaseOrderDetail,String type) {
    if(supplierAccountPeriodMap == null)
      return false;
    if(purchaseOrderDetail == null)
      return false;
    String supplierName = purchaseOrderDetail.getSupplierName();
    if(supplierName == null)
      return false ;
    SupplierAccountPeriod SupplierAccountPeriod = supplierAccountPeriodMap.get(supplierName);
    if(SupplierAccountPeriod == null){
      purchaseOrderDetailList.forEach(
          po-> {
            po.setIfSpecial(false);
            po.setExpectPayDate("未找到供应商账期");
          }
      );
      return false;
    }
    //获得账期
    String realNeedAddDay = SupplierAccountPeriod.getRealNeedAddDay();
    String date = purchaseOrderDetail.getInventoryDate();
    if(date == null)
      return false;
    String newDate = dateAddAccountPeriod(date,realNeedAddDay);
    for(PurchaseOrderDetail p : purchaseOrderDetailList){
      p.setExpectPayDate(newDate);
      p.setNeedPayAmount(p.getInventoryMoney());
    }
    purchaseOrderDetailList.forEach(
        pod->
        {
          pod.setType("NYN");
          pod.setIfSpecial(false);
        }
    );
    return true;
  }
}
